<template>
  <div class="app-container">
    <el-row class="app-container__top">
      <el-col :span="12">
        <span>真实流水：{{tableData.bet}}</span>
      </el-col>
      <el-col :span="12">
        <el-button type="primary" size="medium" @click="dialogFlag=true">添加假流水</el-button>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <div class="app-container__title">流水更改记录</div>
        <el-table :data="tableData.list">
          <el-table-column label="更改时间" align="center" prop="date">
          </el-table-column>
          <el-table-column label="更改数值" align="center" prop="fakeNum"></el-table-column>
          <el-table-column label="更改后显示总流水" align="center" prop="afterBet"></el-table-column>
        </el-table>
      </el-col>
    </el-row>
    <el-dialog title="添加假流水" :visible.sync="dialogFlag" v-if="dialogFlag" width="30%" @close="resetForm">
      <el-form :model="form" ref="form" :rules="rules">
        <el-form-item label="" prop="fakeNum">
          <el-input size="medium" v-model="form.fakeNum" placeholder="请输入流水" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFlag = false;form.fakeNum = 0">取 消</el-button>
        <el-button type="primary" @click="saveForm">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { addAmericaCupFlow, getAmericaCupModifyList } from '@/services/api/activity';
import { form, factory } from '@/build';
import getCommand from '@/mixins/getCommand';

export default {
  name: 'list-one',
  mixins: [form, factory, getCommand],
  data() {
    return {
      dialogFlag: false,
      submitFlag: false, // 防止重复提交
      form: {
        fakeNum: 0,
      },
      tableData: {
        list: [],
        bet: undefined,
      },
      rules: {
        fakeNum: [
          { validator: factory.getValidator('createNoStartWithZero') },
        ],
      },
    };
  },
  mounted() {
    this.bindSave(addAmericaCupFlow, 'saveForm', 'form', {
      afterSuccess: ([result, data]) => {
        if (result) {
          this.dialogFlag = false;
          this.resetForm();
          this.getModifyList();
        }
      },
    });
    this.bindGet(getAmericaCupModifyList, 'tableData', {
      action: 'getModifyList',
    });
    this.getModifyList();
  },
  methods: {
    resetForm() {
      this.form.fakeNum = 0;
    },
    getModifyList() {
      this.doGet({ action: 'getModifyList' });
    },
    saveForm() {
      if (this.submitFlag) {
        return;
      }
      this.submitFlag = true;
      setTimeout(() => {
        this.submitFlag = false;
      }, 1000);
      this.doSave({ action: 'saveForm', form: 'form' });
    },
  },
};
</script>

<style lang="scss" scoped>
  .app-container__top{
    margin-bottom: 40px;
  }
  .app-container__title{
    margin-bottom: 20px;
  }
</style>
